<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page contentType="text/html;charset=UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">
		<link href="themes/css/ui.common.css" rel="stylesheet" type="text/css" />
		<link href="themes/css/ui.child.css" rel="stylesheet" type="text/css" />
		<link href="themes/css/ui.tips.css" rel="stylesheet" type="text/css" />
		<link href="style/jquery_ui/jquery-ui-1.8.custom.css" rel="stylesheet"
			type="text/css" />
		<link id="skin_css" rel="stylesheet" type="text/css"
			href="themes/css/ui.c.blue.css"></link>
		<link rel="stylesheet" href="themes/default/pagination.css"
			type="text/css"></link>
		<link rel="stylesheet" href="themes/css/ui.validation.css" type="text/css"></link>
		<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
		<script src="Scripts/jquery-ui-1.8.custom.min.js"
			type="text/javascript"></script>
		<script src="Scripts/ui.tips.js" type="text/javascript"></script>
		<script src="Scripts/ui.default.js " type="text/javascript"
			charset="UTF-8"></script>
		<script src="Scripts/ui.admincp.js" type="text/javascript"
			charset="UTF-8"></script>
		<script type="text/javascript" src="Scripts/jquery.json-2.2.min.js"></script>
		<STYLE type="text/css">
		.editorArea {
			display: none;
		}
		</STYLE>
		<script type="text/javascript" src="Scripts/ui.dialogFormHelper.js"></script>
		<script type="text/javascript" src="Scripts/ui.validation.js"></script>
		<script type="text/javascript">
		$(function () {
			//setValidate();
			queryStudent();
			switcher();
		});
		
		var checkGoodInfoIds ="";
		var unCheckGoodInfoIds ="";
		
		function setValidate(){  
	   		$("#form").validatingForm({
	      	  submitButtonId:"#btnSubmit",
	     	  clearErrorsOnFocus:true,
	      	  validateOnBlur:true
	       });
	    }
		
		function queryStudent(){
			var stuNo = $("#stuNo").val();
			var receiveId = $("#receiveId").val();
			$.post("studentInfo!queryByStuNo.action", {"stuNo":stuNo},
			function (data) {
				var jsonData = $.evalJSON(data);
				
				var avatarId = jsonData.avatarInfo.avatarId;
				var gender = jsonData.stuDetail.gender;
				$("#txt_stuId").val(jsonData.id);
				$("#txt_stuNo").text(jsonData.stuNo);
				$("#txt_stuName").text(jsonData.stuName);
				$("#txt_idCard").text(jsonData.stuDetail.idCard);
				$("#dl_gender").text(jsonData.stuDetail.gender);
				if(jsonData.mailInfo != null)
				$("#txt_mail").text(jsonData.mailInfo.mail);
				if(jsonData.stuDetail!=null){
					$("#txt_hometown").text(jsonData.stuDetail.hometown);
					$("#dl_politician").text(jsonData.stuDetail.politician);
					$("#txt_telphone").text(jsonData.stuDetail.telphone);
					$("#txt_grade").text(jsonData.stuDetail.grade);
					$("#txt_classNo").text(jsonData.stuDetail.classNo);
					$("#txt_cardId").text(jsonData.stuDetail.cardId);
					if(jsonData.stuDetail.majorInfo != null)
					$("#txt_majorName").text(jsonData.stuDetail.majorInfo.majorName);
				}
				document.getElementById("img_photo").src = "getPhoto.action?avatarId="+avatarId+"&gender="+gender;
			});
			
			$.post("goodReceived!queryGoodByReceiveId.action", {"id":receiveId},
				function (data) {
				var jsonData = data.split("||");
				$("#receiveInfo").html("");
				$("#receiveInfo").append(jsonData[0]);
				var goodIdArr = jsonData[1].split(",");
				foreachHandler(goodIdArr,function(item){
		        	$("#cb_goodInfo_"+item).attr("checked","checked");
		        	$("#cb_goodInfo_"+item).attr("disabled",true);
		        });
			});
		}
		
		function switcher() {		    
		    $("#btn_Submit").click(function(){
		    	var receiveId = $("#receiveId").val();
		    	var stuId = $("#txt_stuId").val();
		    	var stuNo = $("#stuNo").val();
		    	getGoodIds();
		    	if(checkGoodInfoIds != "")
		    	checkGoodInfoIds = checkGoodInfoIds.substring(0,checkGoodInfoIds.length-1);
		    	if(unCheckGoodInfoIds != "")
		    	unCheckGoodInfoIds = unCheckGoodInfoIds.substring(0,unCheckGoodInfoIds.length-1);

		    	$.post("goodReceived!receiveGood.action", {"stuNo":stuNo,"stuId":stuId, "id": receiveId, "checkGoodInfoIds":checkGoodInfoIds, "unCheckGoodInfoIds":unCheckGoodInfoIds }, function (data) {
		    		if(data == 1){
		    			alert("领取成功");
		    			location="goodReceived!toReceive.action?id="+receiveId+"&stuNo="+$("#stuNo").val();
		    		}
		    		if(data == 2){
		    			alert("全部领取成功");
		    			location.href="goodReceived!toShow.action";
		    		}
					if(data == -1){
		    			alert("领取失败");
		    		}
		    	});
		    	
		    });
		}
		
		function getGoodIds(){
			checkGoodInfoIds  ="";
			unCheckGoodInfoIds ="";
			
			var dataInControls = $(".cb_goodInfo");

			dataInControls.each(function(item){
				var id = $(dataInControls[item]).val();
				if($(dataInControls[item]).attr("checked")==""){
					unCheckGoodInfoIds += id +","; 
				}
				else{
					checkGoodInfoIds += id +","; 
				}
			});
		}
		</script>
	</head>
	<body>
		<div class="PageChild_Title">
			<img src=" themes/images/default/icons/archives.png"
				class="PageChild_Tbtnpic" />
			<span class="PageChild_separate"></span>
			<span class="PageChild_TbtnText">
				<h2>领取物品</h2>
			</span>
			<span class="PageChild_separate"></span>
			<div id="marker" class="red-tips">
			</div>
			<div class="clear">
			</div>
		</div>
		<s:form action="">
		<table  id="form" style="border: 1px solid gray; padding: 1px;" border="0"
			cellpadding="0" cellspacing="0" align="center">
			<tr>
				<td colspan="8" align="center">
					<input id="stuNo" type="hidden" value="${stuNo}">
					<input id="receiveId" type="hidden" value="${id}">
					<s:hidden id="txt_stuId" name="stuId" theme="simple"/>
				</td>
			</tr>
			<tr>
				<td colspan="8" align="center">
					<b>基本信息</b>
				</td>
			</tr>
			<tr>
				<td class="text-align-right" style="width: 80px;">
					&nbsp;学号:
				</td>
				<td style="width: 110px" valign="middle" class="style1">
					<label id="txt_stuNo"></label>&nbsp;
				</td>
				<td class="text-align-right" style="width: 80px;">
					&nbsp;姓名:
				</td>
				<td style="width: 110px" valign="middle" class="style1">
					<label id="txt_stuName"></label>&nbsp;
				</td>
				<td class="text-align-right" style="width: 80px;">
					&nbsp;银行卡号:
				</td>
				<td style="width: 110px" valign="middle" class="style1">
					<label id="txt_cardId"></label>&nbsp;
				</td>
				<td style="width: 300px" valign="middle" align="center" class="style1" rowspan="4" colspan="2">
					<img id="img_photo" alt="一寸照片" src="getPhoto.action"><br />
				</td>
			</tr>
			<tr>
				<td class="text-align-right" style="width: 80px;">
					&nbsp;性别:
				</td>
				<td style="width: 110px" valign="middle" class="style1">
					<label id="dl_gender"></label>&nbsp;
				</td>
				<td class="text-align-right" style="width: 80px;">
					&nbsp;身份证号:
				</td>
				<td style="width: 110px" valign="middle" class="style1">
					<label id="txt_idCard"></label>&nbsp;
				</td>
				<td class="text-align-right" style="width: 80px;">
					&nbsp;邮箱:
				</td>
				<td style="width: 110px" valign="middle" class="style1">
					<label id="txt_mail"></label>&nbsp;
				</td>
			</tr>
			<tr>
				<td class="text-align-right" style="width: 80px;">
					&nbsp;家乡:
				</td>
				<td style="width: 110px" valign="middle" class="style1">
					<label id="txt_hometown"></label>&nbsp;
				</td>
				<td class="text-align-right" style="width: 80px;">
					&nbsp;政治面貌:
				</td>
				<td style="width: 110px" valign="middle" class="style1">
					<label id="dl_politician"></label>&nbsp;
				</td>
				<td class="text-align-right" style="width: 80px;">
					&nbsp;手机号码:
				</td>
				<td style="width: 110px" valign="middle" class="style1">
					<label id="txt_telphone"></label>&nbsp;
				</td>
			</tr>
			<tr>
				<td class="text-align-right" style="width: 80px;">
					&nbsp;专业:
				</td>
				<td style="width: 130px" valign="middle" class="style1">
					<label id="txt_majorName"></label>&nbsp;
				</td>
				<td class="text-align-right" style="width: 80px;">
					&nbsp;年级:
				</td>
				<td style="width: 110px" valign="middle" class="style1">
					<label id="txt_grade"></label>&nbsp;
				</td>
				<td class="text-align-right" style="width: 80px;">
					&nbsp;班级:
				</td>
				<td style="width: 110px" valign="middle" class="style1">
					<label id="txt_classNo"></label>&nbsp;
				</td>
			</tr>
			<tr>
				<td colspan="8" align="center">
					<b>领取物品详情</b><input id="payIds" name="payIds" type="hidden">
				</td>
			</tr>
			<tr>
				<td class="text-align-right" style="width: 100px;">
					&nbsp;领取物品类型
				</td>
				<td class="text-align-right" style="width: 100px;" colspan="7">
					&nbsp;物品详细信息
				</td>
			</tr>
			<tr id="receiveInfo">
			</tr>
			<tr>
				<td colspan="8" align="center">
					<input type="button" id="btn_Submit" class="o-btn" value="领取">
				</td>
			</tr>
			<tr>
				<td colspan="8" align="center">
					&nbsp;
				</td>
			</tr>
		</table>
		</s:form>
		<div id="errorSummary"></div>
	</body>
</html>